package cn.zjitc.quickstart.user.dao.impl;

import cn.zjitc.quickstart.user.dao.UserDao;
import cn.zjitc.quickstart.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl implements UserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public User findByUsernameAndPassword(String name, String password) {
        User user = null;
        try {
            user = jdbcTemplate.queryForObject("select * from user where name=? and password=?", new BeanPropertyRowMapper<User>(User.class), name, password);
        } catch (DataAccessException e) {
            return null;
        }
        return user;
    }
}
